﻿//-----------------------------------------------------------------
//
// @(#)$Id: left.aspx.cs,v 1.0 2013/12/16 9:56:05 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:56:05 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_SystemTableAdapters;

public partial class left : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            Response.Write("<script>alert('请先登陆!');");
            Response.Redirect("Login.aspx");
        }
    }

    protected string GetRight()
    {
        System.Text.StringBuilder memuBuilder = new System.Text.StringBuilder();
        DataTable tableMemu = new T_MemuContextTableAdapter().GetUserMemuByUserId(Session["UserId"].ToString());
        DataTable tableRight = new T_RightContextTableAdapter().GetUserRightByUserId(Session["UserId"].ToString());

        int i = 0;
        DataRow[] nRow = tableMemu.Select("","SortId");
        memuBuilder.Append("<div class=\"LeftNote\"><img src=\"Images/MenuTop.jpg\" style=\"width: 182px\"/><br /><img src=\"Images/menu_topline.gif\" alt=\"\"/>");
        foreach (DataRow rNo in nRow)
        {
            memuBuilder.Append(" <div class=\"Menu\">&nbsp;<img  class=\"MemuImg\"  src=\"Images/" + rNo["PicName"].ToString() + "\"/>&nbsp;" + rNo["SysName"].ToString() + "</div>").Append("\r\n");

            if (i == 0)
            {
                memuBuilder.Append("<div class=\"MenuNote\" style=\"display:block;\">").Append("\r\n");
            }
            else
            {
                memuBuilder.Append("<div class=\"MenuNote\" style=\"display:none;\">").Append("\r\n");
            }
            memuBuilder.Append("<img src=\"images/menu_topline.gif\" alt=\"\" />").Append("\r\n");
            string newChildNode = "";
            string oldChildNode = "";
            DataRow[] cRow = tableRight.Select("SysId='" + rNo["SysId"].ToString() + "'","SortId1");
            foreach (DataRow r in cRow)
            {
                newChildNode = r["SubSysId"].ToString();
                if (oldChildNode != newChildNode)
                {
                    memuBuilder.Append("<div class=\"CMenu\">&nbsp;" + r["SubSysName"].ToString() + "</div>").Append("\r\n");
                    memuBuilder.Append("<div class=\"CMenuNote\" style=\"display:block;\">").Append("\r\n");
                    memuBuilder.Append("<ul class=\"MenuUL\">").Append("\r\n");
                    oldChildNode = newChildNode;

                    DataRow[] rs = tableRight.Select("SubSysId='" + newChildNode + "'");

                    foreach (DataRow rm in rs)
                    {
                        memuBuilder.Append("<li><a href=\"" + rm["ProgExecName"].ToString() + "\" target=\"main\"> &nbsp;&nbsp;&nbsp;&nbsp;" + rm["ProgName"].ToString() + "</a></li>").Append("\r\n");
                    }
                    memuBuilder.Append("</ul>").Append("\r\n");
                    memuBuilder.Append("</div>").Append("\r\n");
                }
            }
            i++;
            memuBuilder.Append("</div>").Append("\r\n");
        }
        return memuBuilder.ToString();
    }
}